<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tab栏</title>
    <style>
        .tabtop {
            width: 200px;
            height: 200px;
        }
        
        ul {
            display: block;
            list-style: none;
            width: 200px;
            height: 200px;
            background-color: aqua;
        }
        
        ul li {
            display: block;
            height: 50px;
            width: 90px;
            text-align: center;
            line-height: 50px;
            float: left;
            border: 1px solid red;
        }
        
        .current {
            background-color: brown;
        }
        
        .tabfoot {
            width: 200px;
            height: 200px;
        }
        
        .tabfoot div {
            display: none;
        }
    </style>
</head>

<body>
    <!-- tab栏标签切换分析：重点案例 -->
    <div class="tab">
        <div class="tabtop">
            <ul>
                <li class="current">你好</li>
                <li>好的</li>
            </ul>
        </div>
        <div class="tabfoot">
            <div style="display: block;">世界</div>
            <div>我知道</div>
        </div>
    </div>
    <script>
        var tabtop = document.querySelector('ul');
        var tabtopli = document.querySelectorAll('li');
        var tabfoot = document.querySelectorAll('.tabfoot div');
        for (var i = 0; i < tabtopli.length; i++) {
            tabtopli[i].setAttribute('index', i);
            tabtopli[i].onclick = function() {
                for (var i = 0; i < tabtopli.length; i++) {
                    tabtopli[i].className = '';
                }
                this.className = 'current';
                var index = this.getAttribute('index');
                console.log(index);
                for (var i = 0; i < tabfoot.length; i++) {
                    tabfoot[i].style.display = 'none';
                }
                tabfoot[index].style.display = 'block';
            }
        }
    </script>
</body>

</html>